package controller;

import com.opensymphony.xwork2.ActionContext;
import help.Pagination;
import java.util.ArrayList;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.RequestMap;
import org.apache.struts2.dispatcher.mapper.ActionMapping;

public class AppController {

    ArrayList<Pagination> pagination = new ArrayList();
    public int page_size = 10;
    public int page_number = 1;
    public int total = 0;
    String error = "";
    String message = "";
    String urlvalid = "";
    
    //views
    public String error() {
        return "error";
    }   
    //end views
   

    public String getMessage() {
        //Map session = ActionContext.getContext().getSession();
        //message = session.get("message").toString();
        return message;
    }

    public void setMessage(String message) {
        //Map session = ActionContext.getContext().getSession();
        //session.put("message", message);
        this.message = message;
    }

    public String getError() {
        //Map session = ActionContext.getContext().getSession();
        //error = session.get("error").toString();
        return error;
    }

    public void setError(String error) {
        //Map session = ActionContext.getContext().getSession();
        //session.put("error", error);
        this.error = error;
    }

    public int getPage_number() {
        return page_number;
    }

    public void setPage_number(int page_number) {
        this.page_number = page_number;
    }

    public int getPage_size() {
        return page_size;
    }

    public void setPage_size(int page_size) {
        this.page_size = page_size;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public ArrayList<Pagination> getPagination() {
        int t = ((total % page_size) == 0) ? (total / page_size) : (total / page_size + 1);
        for (int x = 1; x < t + 1; x++) {
            if (x == page_number) {
                pagination.add(new Pagination(String.valueOf(x), "true"));
            } else {
                pagination.add(new Pagination(String.valueOf(x), "false"));
            }
        }
        return pagination;
    }

    public void setPagination(ArrayList<Pagination> pagination) {
        this.pagination = pagination;
    }

    public boolean isGet() {
        HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
        String method = request.getMethod();
        if (method.equals("GET")) {
            return true;
        }
        return false;
    }

    public boolean isPost() {
        HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
        String method = request.getMethod();
        if (method.equals("POST")) {
            return true;
        }
        return false;
    }

    public String getUrlvalid() {
        return urlvalid;
    }

    public void setUrlvalid(String urlvalid) {
        this.urlvalid = urlvalid;
    }
}
